//
//  MyWalletController.m
//  cooba-iOS
//
//  Created by 郭四虎 on 16/9/9.
//  Copyright © 2016年 YouKu. All rights reserved.
//

#import "MyWalletController.h"
#import "ReflectMoneyController.h"
#import "RedPacketDetailViewController.h"

@interface MyWalletController ()
{
    CGFloat _drawMoney;
}
@property (weak, nonatomic) IBOutlet UILabel *money;
@property (weak, nonatomic) IBOutlet UIButton *noti;
@property (weak, nonatomic) IBOutlet UIButton *reflectBtn;

@end

@implementation MyWalletController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    _noti.layer.cornerRadius = 10;
    
    self.title = @"钱包";
    UIButton *rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [rightBtn setTitle:@"明细" forState:UIControlStateNormal];
    [rightBtn setFrame:CGRectMake(0, 0, 50, 30)];
    rightBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
    [rightBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    rightBtn.titleLabel.font =[UIFont systemFontOfSize:17 weight:UIFontWeightThin];
    [rightBtn addTarget:self action:@selector(showDetali) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *bar = [[UIBarButtonItem alloc]initWithCustomView:rightBtn];
    self.navigationItem.rightBarButtonItem = bar;
    
    [MyRedPacket myWallet:^(BOOL suc, NSDictionary *dic) {
        
        if (suc) {
            
            _money.text = [dic[@"money"] integerValue]?dic[@"money"]:@"0.00";
            _drawMoney = ((NSString *)[dic objectForKey:@"drawMoney"]).floatValue;
            
        }else{
            
            _money.text = @"0.00";
        }
    }vc:self];
}
- (IBAction)showNoti:(UIButton *)sender {
    
    NSString *msg = [NSString stringWithFormat:@"余额满 %.2f 元才可以申请提现",_drawMoney?_drawMoney:10];
    
    MyView *v = [[MyView alloc]initWithFrame:SCREEN startPoint:[sender.superview convertPoint:CGPointMake(sender.center.x, sender.center.y+30) toView:self.view] msg:msg];
    [self.view addSubview:v];
}
- (IBAction)reflectMoney:(id)sender {
    
//    if (_money.text.floatValue<_drawMoney) {
//        
//        [self.view Message:@"余额不足以提现"];
//        return;
//    }
    if (![Myuser valiMobile:[Myuser sharedUser].login_id]) {
        
        [self.view Message:@"暂未绑定手机号"];
        return;
    }

    ReflectMoneyController *vc = [[ReflectMoneyController alloc]init];
    vc.drawMoney = _drawMoney;
    vc.money = _money.text;
    vc.back = ^(NSString *money){
        
        _money.text = money;
    };
    [self.navigationController pushViewController:vc animated:YES];
}
- (IBAction)reflectRecord:(id)sender {
    
    RedPacketDetailViewController *detail = [[RedPacketDetailViewController alloc]init];
    detail.isReflect = YES;
    [self.navigationController pushViewController:detail animated:YES];
}

- (void)showDetali
{
    RedPacketDetailViewController *detail = [[RedPacketDetailViewController alloc]init];
    detail.isReflect = NO;
    [self.navigationController pushViewController:detail animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
